<template>
    <div>
        <div class="logo_content">
            <img :src="$store.getters.base_url+userInfo.logo" alt="" class="logo">
            <div class="upload_box">
                <Upload title="用户头像" @getImg="getImg"></Upload>
            </div>
        </div>
        <mt-field label="店铺名称" placeholder="请输入店铺名称" v-model="userInfo.shop_name"></mt-field>
        <mt-field label="公告" placeholder="请输入店铺公告" v-model="userInfo.describe"></mt-field>
        <mt-field label="开始营业时间" placeholder="请输入开始营业时间" type="time" v-model="userInfo.send_start"></mt-field>
        <mt-field label="结束营业时间" placeholder="请输入结束营业时间" type="time" v-model="userInfo.send_end"></mt-field>
        <section class="login_message">
            <mt-button class="btn" @click="edit">修改</mt-button>
        </section>
    </div>
</template>
<script>
import Upload from "../components/upload";
import {Toast} from 'mint-ui'
import {editBasic} from '../api'
export default {
    data() {
        return {
            userInfo:{}
        }
    },
    created(){
        this.getUserInfo();
    },
    methods:{
        getUserInfo(){
            this.userInfo = this.$store.getters.userInfo
        },
        getImg(data){
            console.log(data);
            this.userInfo.logo = data[0];
        },
        edit(){
            let data = {
                token:this.$store.getters.token,
                shop_name:this.userInfo.shop_name,
                logo:this.userInfo.logo,
                describe:this.userInfo.describe,
                send_start:this.userInfo.send_start,
                send_end:this.userInfo.send_end
            }
            if(!data.shop_name){
                Toast("请输入商户名称")
                return;
            }else if(!data.logo){
                Toast("请选择上传图片")
                return;
            }else if(!data.send_start){
                Toast("请输入开始营业时间")
                return
            }else if(!data.send_end){
                Toast("请输入结束营业时间")
                return
            }else if(!data.describe){
                Toast("请输入店铺公告")
                return
            }else if(data.send_start>=data.send_end){
                Toast("开始营业时间应小于等于结束营业时间")
                return
            }
            editBasic(data).then(res=>{
                console.log(res);
                Toast(res.msg)
            })
        }
    },
    components: { Upload },
}
</script>
<style scoped>
    .logo_content{
        width: 6rem;
        height: 6rem;
        margin: 2rem auto;
    }
    .logo{
        width: 100%;
        height: 100%;
        border-radius: 50%;
    }
    .mint-cell{
        border-bottom: 1px solid #ccc;
    }
    .upload_box{
        position: absolute;
        top: 3rem;
        opacity: 0;
    }
    .btn{
        background: #F0463C;
        color: #fff;
    }
</style>